package com.zh.plus;

import com.zh.entity.User;
import com.zh.service.AuthTongdunService;
import com.zh.service.impl.AuthTongdunServiceImpl;
import com.zh.util.UserContext;
import com.zh.util.dict.CodeMsg;
import com.zh.util.dict.RedisKey;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import redis.clients.jedis.Jedis;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Service
public class AccessInterceptor extends BaseInterceptor {

    @Resource
    private RedisTemplate<Object,Object> redisTemplate;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String token = request.getParameter("token");
        System.out.println("++++"+token);
        if (StringUtils.isEmpty(token)) {
            render(response, CodeMsg.SESSION_ERROR);
            return false;
        }
//        System.out.println("-----------"+redisTemplate);
//        System.out.println(redisTemplate.opsForValue().get(RedisKey.USER_TOKEN.getKey()+token));
//        User user = (User)redisTemplate.opsForValue().get(RedisKey.USER_TOKEN.getKey()+token);

//        if (token == null) {
//            render(response, CodeMsg.SESSION_ERROR);
//            return false;
//        }

//        UserContext.setUser(user);
        return true;

    }
}
